package com.zide.job.mapper;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.common.core.domain.PageResult;
import com.zide.framework.config.mybatisplus.XianYingMapperPlus;
import com.zide.job.domain.SysJobLog;
import com.zide.job.domain.vo.SysJobLogSearchVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 调度任务日志信息 数据层
 *
 * @author zide
 */
@Mapper
public interface SysJobLogMapper extends XianYingMapperPlus<SysJobLog> {
    /**
     * 获取quartz调度器日志的计划任务
     *
     * @param jobLog 调度日志信息
     * @return 调度任务日志集合
     */
    public List<SysJobLog> selectJobLogList(SysJobLog jobLog);

    /**
     * 查询所有调度任务日志
     *
     * @return 调度任务日志列表
     */
    public List<SysJobLog> selectJobLogAll();

    /**
     * 通过调度任务日志ID查询调度信息
     *
     * @param jobLogId 调度任务日志ID
     * @return 调度任务日志对象信息
     */
    public SysJobLog selectJobLogById(Long jobLogId);

    /**
     * 新增任务日志
     *
     * @param jobLog 调度日志信息
     * @return 结果
     */
    public int insertJobLog(SysJobLog jobLog);

    /**
     * 批量删除调度日志信息
     *
     * @param logIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteJobLogByIds(Long[] logIds);

    /**
     * 删除任务日志
     *
     * @param jobId 调度日志ID
     * @return 结果
     */
    public int deleteJobLogById(Long jobId);

    /**
     * 清空任务日志
     */
    public void cleanJobLog();

    default PageResult<SysJobLog> selectPage(SysJobLogSearchVO searchVO) {
        LambdaQueryWrapper<SysJobLog> wrapper = new LambdaQueryWrapper<>();
        if(StrUtil.isNotEmpty(searchVO.getJobName())) {
            wrapper.like(SysJobLog::getJobName,searchVO.getJobName());
        }
        if(StrUtil.isNotEmpty(searchVO.getJobGroup())) {
            wrapper.eq(SysJobLog::getJobGroup,searchVO.getJobGroup());
        }
        if(ObjectUtil.isNotNull(searchVO.getStatus())) {
            wrapper.eq(SysJobLog::getStatus,searchVO.getStatus());
        }

        return selectPage(searchVO,wrapper);
    }

}
